﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 玩具商城管理系统.znew
{
    public partial class Tcommoditypj : Form
    {
        public Tcommoditypj()
        {
            InitializeComponent();
        }
        void showAll()
        {
            DB.GetCn();
            string str = "select * from hot where hot_commodityname=(select commodity_name from commodity where commodity_id=" + newwin.Commodityid+ ") and (hot_language IS NOT NULL or hot_phto IS NOT NULL)";
            string noshow; 
            SqlCommand cmd = new SqlCommand(str, DB.cn);
            SqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                
                int index = dgvpj.Rows.Add();
                if (!Convert.IsDBNull(rdr[13]))
                {
                     noshow = (string)rdr[13];
                }
                else
                {
                    noshow = "";
                }
                if (noshow == "yes")
                {
                    dgvpj.Rows[index].Cells[0].Value = "***";
                }
                else
                {

                    dgvpj.Rows[index].Cells[0].Value = rdr[7];
                }
                dgvpj.Rows[index].Cells[1].Value = rdr[8]; 

            }
            rdr.Close();
        }

        private void Tcommoditypj_Load(object sender, EventArgs e)
        {
            this.dgvpj.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            dgvpj.RowTemplate.Height = 40;
            showAll();

            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dgvpj_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DB.GetCn();
            string str = "select * from hot where hot_commodityname=(select commodity_name from commodity where commodity_id=" + newwin.Commodityid + ")";
           
            int CIndex = e.ColumnIndex;
            int RIndex= e.RowIndex;
            if (CIndex == 2)
            {
                DB.GetCn();
                DataTable dt = DB.GetDataSet(str);
                string sdr = "select * from client where client_name='"+dgvpj.Rows[RIndex].Cells[0].Value.ToString()+"'";
                DataTable dt2 = DB.GetDataSet(sdr);
                if (dt.Rows[RIndex][13].ToString() == "yes")
                {

                    label4.Text = "匿名用户";
                }
                else
                {

                    label4.Text = dt.Rows[RIndex][7].ToString();
                }
                label5.Text = dt.Rows[RIndex][8].ToString();
                label7.Text = dt.Rows[RIndex][5].ToString();
                label8.Text = dt.Rows[RIndex][12].ToString();
                if (dt.Rows[RIndex][13].ToString() == "yes")
                {
                    try
                    {
                        pictureBox4.Image = Image.FromFile(Application.StartupPath + "\\" + "人1.jpg");
                        pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
                    }
                    catch
                    {
                        pictureBox4.Image = Image.FromFile(Application.StartupPath + "\\" + "人1.jpg");
                        pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
                    }
                }
                else
                {
                    try
                    {
                        pictureBox4.Image = Image.FromFile(Application.StartupPath + dt2.Rows[0][10].ToString());
                        pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
                    }
                    catch
                    {
                        pictureBox4.Image = Image.FromFile(Application.StartupPath + "\\" + "人1.jpg");
                        pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
                    }
                }
                try
                {
                    pictureBox1.Image = Image.FromFile(Application.StartupPath + dt.Rows[RIndex][9].ToString());
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox1.Visible = true;
                }
                catch
                {
                    pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\" + "暂无图片.gif.jpg");
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox1.Visible = false;
                }
                try
                {
                    pictureBox2.Image = Image.FromFile(Application.StartupPath + dt.Rows[RIndex][10].ToString());
                    pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox2.Visible = true;

                }
                catch
                {
                    pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\" + "暂无图片.gif.jpg");
                    pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox2.Visible = false;
                }
                try
                {
                    pictureBox3.Image = Image.FromFile(Application.StartupPath + dt.Rows[RIndex][11].ToString());
                    pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox3.Visible = true;
                }
                catch
                {
                    pictureBox3.Image = Image.FromFile(Application.StartupPath + "\\" + "暂无图片.gif.jpg");
                    pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox3.Visible = false;
                }
                groupBox1.Visible = true;
            }
            else
            {
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            groupBox1.Visible= false;
        }
    }
}
